/*
ID:luonghp3
LANG:JAVA
TASK:nuggets
*/

import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;


public class nuggets {

	public static Scanner scanner = null;
	public static PrintStream ps = null;
	public static PrintStream stdout = System.out;
	public static int N;
	public static int[] n;
	public static boolean[] cando = new boolean[1000000];
	public static int allGCD;
	
	public static void main(String[] args) throws Exception {
		
		scanner = new Scanner(new File("nuggets.in"));
		ps = new PrintStream(new File("nuggets.out"));
		System.setOut(ps);
		
		N = scanner.nextInt();
		n = new int[N];
		allGCD = 0;
		for (int i=0;i<N;++i) {
			n[i] = scanner.nextInt();
			cando[n[i]] = true;
			if (i==0) allGCD = n[i];
			else allGCD = gcd(allGCD,n[i]);
		}
		Arrays.sort(n);
		
//		solve_1();
		solve_2();
		
		
		ps.close();
		System.setOut(stdout);
		
	}
	
	private static void solve_2() {

		if (allGCD > 1) {
			System.out.println(0); // have no limit for the largest unpresentable number
		}
		else {
			if (cando[1]) {
				System.out.println(0); // can present any number
			}
			else {
				
				int largest = -1;
				for (int i=0;i<=70000;++i) {
					if (cando[i]) {
						for (int j=0;j<N;++j) {
							cando[i + n[j]] = true;
						}		
					}
					else {
						largest = i;
					}
				}
				
				System.out.println(largest);
			}
		}		
		
	}
	
	private static void solve_1() {

		if (allGCD > 1) {
			System.out.println(0); // have no limit for the largest unpresentable number
		}
		else {
			if (cando[1]) {
				System.out.println(0); // can present any number
			}
			else {
				int startcando = -1;
				int counter = 2;
				while (true) {
					if (cando[counter]) {
						if (startcando == -1) {
							startcando = counter;
						}
						if (counter - startcando + 1 == 256) {
							System.out.println(startcando - 1); // the largest unrepresentable number
							break;
						}
						else {
							for (int i=0;i<N;++i) {
								cando[counter + n[i]] = true;
							}
						}
					}
					else {
						startcando = -1;
					}
					counter++;
				}
			}
		}		
		
	}

	public static int gcd(int a, int b) {
		if (a == 0) 
			return b;
		else
			return gcd(b%a,a);
	}
	
}
